package com.woniu.advice;

import com.woniu.util.R;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.SignatureException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 *
 * 全局异常处理类：统一处理我们的异常（程序错误或请求错误）
 */

@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(ExpiredJwtException.class)
    public R expiredJwtException(ExpiredJwtException e){
        return R.build(501, e.getMessage(),null );
    }

    @ExceptionHandler(SignatureException.class)
    public R signatureException(SignatureException e){
        return R.build(501, e.getMessage(),null );
    }

    @ExceptionHandler(CodeException.class)
    public R codeException(CodeException e){
        return R.build(501, e.getMessage(),null );
    }

    @ExceptionHandler(RuntimeException.class)
    public R runtimeException(RuntimeException e){
        return R.build(501, e.getMessage(),null );
    }
}
